import 'package:flutter/material.dart';
import 'package:flutter_trip/base_view/base_appbar.dart';

const CITY_NAMES = {
  '北京': ['东城区', '西城区', '朝阳区', '丰台区', '石景山区', '海淀区', '顺义区'],
  '上海': ['黄浦区', '徐汇区', '长宁区', '静安区', '普陀区', '闸北区', '虹口区'],
  '广州': ['越秀', '海珠', '荔湾', '天河', '白云', '黄埔', '南沙', '番禺'],
  '深圳': ['南山', '福田', '罗湖', '盐田', '龙岗', '宝安', '龙华'],
  '杭州': ['上城区', '下城区', '江干区', '拱墅区', '西湖区', '滨江区'],
  '苏州': ['姑苏区', '吴中区', '相城区', '高新区', '虎丘区', '工业园区', '吴江区']
};

class MyExpansionList extends StatefulWidget {
  @override
  _MyExpansionListState createState() => _MyExpansionListState();
}

class _MyExpansionListState extends State<MyExpansionList> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getAppbarLeading('可展开列表',ElevatedButton(onPressed: (){
        Navigator.pop(context);
      }, child: Icon(Icons.arrow_back)),
      ),
      body:Container(child: ListView(children:
        _buildList(),),) ,

    );
  }

  List<Widget> _buildList(){
    List<Widget> widgets = [];
    CITY_NAMES.keys.forEach((key) {
      String key1 = key;
      var subs = CITY_NAMES[key1];
      print(subs);
      widgets.add(_item(key, ['beiji','上海','杭州']));
    });
    return widgets;
  }
  _print(){
    print(CITY_NAMES['']);
  }
  Widget _item(String city, List<String> subCities) {
    return ExpansionTile(
        title: Text(
          city,
          style: TextStyle(color:Colors.black54,fontSize: 20 ),
        ),
        children: subCities.map((subCity) => _buildSub(subCity)).toList(),

    );
  }

  Widget _buildSub(String subCity){
    return FractionallySizedBox(
      widthFactor: 1,
      child: Container(height: 50,
        margin: EdgeInsets.only(bottom: 5),
        decoration: BoxDecoration(color:Colors.lightBlueAccent ),
        child: Text(subCity),
      ),

    );
  }
}
